package cn.wolfcode.web.controller;

import cn.wolfcode.domain.Employee;
import cn.wolfcode.domain.JsonResult;
import cn.wolfcode.domain.Permission;
import cn.wolfcode.service.IAnnouncementService;
import cn.wolfcode.service.IEmployeeService;
import cn.wolfcode.web.util.SessionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class LoginController {

    @Autowired
    private IEmployeeService service;

    @Autowired
    private IAnnouncementService announcementService;

    @RequestMapping("/loginGo")
    @ResponseBody
    public JsonResult login(String username, String password) {
        JsonResult jsonResult = new JsonResult();


        Employee employee = service.checkUser(username, password);
        SessionUtil.setAtt(SessionUtil.USER,employee);

        List<Permission> permission = service.getPermission(employee.getId());
        SessionUtil.setAtt(SessionUtil.PERMISSION, permission);

        return jsonResult;

    }

    @RequestMapping("/error2")
    public String error() {
        return "common/error";
    }

   /* @RequestMapping("/msg")
    public String msg(Model model){
        model.addAttribute("msg",announcementService.selectNoRead(SessionUtil.getAtt(SessionUtil.USER).getId()));
        model.addAttribute("count",announcementService.getCount(SessionUtil.getAtt(SessionUtil.USER).getId()));
        return "common/navbar";
    }*/


}
